package DatabaseManaging;

import java.util.ArrayList;
import java.util.Map;

import DatabaseManaging.Models.Product;


public class ProductBuilder{
	private Product product;

	
	public Product getProduct() {
		return product;
	}


	public void setProduct(Product product) {
		this.product = product;
	}


	public static Product build(String prdLine) {
		String[] record=prdLine.split("\t");
		Product prod=new Product();
		prod.setName(record[1]);
		ArrayList<String> abbs=new ArrayList<String>();
		for(int i=2;i<7;i++){
			if(!record[i].isEmpty()){
			abbs.add(record[i]);
			}
		}
		prod.setAbbs(abbs);
		prod.setRelease(record[7]);
		prod.setRelease_year(record[8]);
		return prod;
	}
	public static Product build(Map record) {
		Product prod=new Product();
		prod.setId((Long)record.get("product_dim_id"));
		prod.setName((String)record.get("product_name"));
		ArrayList<String> abbs=new ArrayList<String>();
		for(int i=0;i<5;i++){
			String abbreviation=(String)record.get("product_abbr"+i);
			if(abbreviation!=null && !abbreviation.isEmpty()){
				abbs.add(abbreviation);
			}
		}
		prod.setAbbs(abbs);
		prod.setRelease((String)record.get("version"));
		prod.setRelease_year((String)record.get("version_abbr"));

		
		return prod;
	}

}
